package moverules;

import java.util.ArrayList;

import board.Board;
import board.Move;
import board.Board.CellType;
import board.Move.Direction;

public class BoxMoveReverseNaive implements MoveRule {

	private boolean canMoveBoxFromHere( Board board, Move move )
	{
//		boolean value = true;
//		
//		return value;
		
        switch ( board.getCellType(move) ) 
        {
	        case Wall: 					return false;
	        case Player: 			return true;
	        case PlayerOnGoalSquare:return true;
	        case Box: 				return true;
	        case BoxOnGoal: 		return true;
	        case GoalSquare: 		return true;
	        case EmptyFloor: 		return true;
	        	
	        default: throw new IllegalArgumentException();
        }
	}
	
	@Override
	public boolean isLegalMove(Board board, Move move, Direction direction) 
	{
		boolean value = true;
		
		int atleastOne = 0;
		
		for ( Direction newDirection : Direction.values() )
		{
			if ( newDirection == direction.reverse() )
			{
				// Pass
			}
			else
			{
				if ( canMoveBoxFromHere(board, move.doNewMove(newDirection)) )
				{
					atleastOne++;
				}
			}
		}
		if ( atleastOne == 0 )
		{
			return false;
		}
		
		
//		Move playerPushPos = move.doNewMove(direction);
//		
//        switch ( board.getCellType(playerPushPos) ) 
//        {
//	        case Wall: 				return false;
//	        case Player: break;
//	        case PlayerOnGoalSquare: break;
//	        case Box: 				return false;
//	        case BoxOnGoal: 		return false;
//	        case GoalSquare: break;
//	        case EmptyFloor: break;
//	        	
//	        default: throw new IllegalArgumentException();
//        }
		
//		value &= ( board.getCellType( playerPushPos ) != CellType.Wall );
//		value &= ( board.getCellType( playerPushPos ) != CellType.Box );
//		
////		Move originalMove = move.doNewMove( direction.reverse() );
//		
//		value &= ( board.getCellType( move ) != CellType.Wall );
//		value &= ( board.getCellType( move ) != CellType.Box );
//		value &= ( board.getCellType( move ) != CellType.BoxOnGoal );
        
        switch ( board.getCellType(move) ) 
        {
	        case Wall: 				return false;
	        case Player: break;
	        case PlayerOnGoalSquare: break;
	        case Box: 				break;
	        case BoxOnGoal: 		break;
	        case GoalSquare: break;
	        case EmptyFloor: break;
	        	
	        default: throw new IllegalArgumentException();
        }
		
		return value;
	}

}
